package cn.hesion.thread.productandconsumer;
/**
 * ClassName: Cooker <br/>
 * Description: <br/>
 * date: 2022/6/6 14:02<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

/**
 * @author: hesion
 * @create: 2022-06-06 14:02
 **/
public class Cooker extends Thread {
    @Override
    public void run() {

        while (true) {
            synchronized (Desk.lock) {
                if (Desk.count == 0) {
                    break;
                } else {
                    if (!Desk.flag) {
                        System.out.println(Thread.currentThread().getName() + " 厨师在做汉堡包");
                        Desk.flag = true;
                        Desk.lock.notifyAll();
                    } else {
                        try {
                            Desk.lock.wait();
                        } catch (InterruptedException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}
